<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title> - 我的素材列表</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link href="/front/hAdmin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/front/hAdmin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/front/hAdmin/css/animate.css" rel="stylesheet">
    <link href="/front/hAdmin/css/style.css?v=4.1.0" rel="stylesheet">

    <link href="/front/hAdmin/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
</head>

<body class="gray-bg">
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-sm-4">
        <h2>素材列表</h2>
        <ol class="breadcrumb">
            <li>
                <a>主页</a>
            </li>
            <li>
                <strong>素材列表</strong>
            </li>
        </ol>
    </div>
    <div class="col-sm-8">
        <div class="title-action">
        </div>
    </div>
</div>

<div class="wrapper wrapper-content">

    <div class="row">
        <div class="col-sm-12">
            <div class="well">
                <form action="javascript:void(0)" name="searchForm">
                    <img src="/images/icon_search.gif" width="26" height="22" border="0" alt="SEARCH">
                    <!-- 品牌 -->
                    上架状态：<select name="is_shelves" id="is_shelves">
                        <option  @if(isset($is_shelves)&&$is_shelves==-1) selected @endif value=-1>全部</option>
                        <option  @if(isset($is_shelves)&&$is_shelves==0) selected @endif  value=0>未上架</option>
                        <option  @if(isset($is_shelves)&&$is_shelves==1) selected @endif  value=1>已上架</option>
                    </select>
                    审核状态：<select name="audit_state" id="audit_state">
                        <option @if($audit_state===-1) selected @endif value=-1>全部</option>
                        <option @if($audit_state===0) selected @endif value=0>未提交</option>
                        <option @if($audit_state===1) selected @endif value=1>审核中</option>
                        <option @if($audit_state===2) selected @endif value=2>已通过</option>
                        <option @if($audit_state==3) selected @endif value=3>未通过</option>
                    </select>
                    <!-- 关键字 -->
                    <input type="button" id="filter_btn" value="筛选" class="button">
                </form>
            </div>
        </div>
        <div class="col-sm-12">
            <div class="ibox float-e-margins">

                <div class="ibox-content">

                    <div id="DataTables_Table_0_wrapper" class="dataTables_wrapper form-inline" role="grid">
                        <div class="row">
                            <div class="col-sm-6">

                            </div>

                        </div>
                        <table class="table table-striped table-bordered table-hover dataTables-example dataTable"
                               id="DataTables_Table_0" aria-describedby="DataTables_Table_0_info">
                            <thead>
                            <tr role="row">
                                <th class="center">素材ID</th>
                                <th class="center">图片</th>
                                <th class="center">单价</th>
                                <th class="center">素材名</th>
                                <th class="center">审核状态</th>
                                <th class="center">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php $i=0;?>
                            @foreach ($source_pics as $source_pic)
                                @if($i%2!=0)
                                    <tr class="gradeA odd" data-tr-id="{{isset($source_pic->source_pic_id)?$source_pic->source_pic_id:''}}">
                                @else
                                    <tr class="gradeA even"data-tr-id="{{isset($source_pic->source_pic_id)?$source_pic->source_pic_id:''}}">
                                        @endif
                                        <td class="center ">{{isset($source_pic->source_pic_id)?$source_pic->source_pic_id:""}}</td>
                                        <td class="hidden-480"><img src="{{isset($source_pic->small_image)?$source_pic->small_image:''}}" width="100" ></td>
                                        <td class="center ">
                                        @if(isset($source_pic->audit_state)&&($source_pic->audit_state==0||$source_pic->audit_state==2))
                                          <input type="number" min=0 step=0.01 name="price" value="{{$source_pic->price}}" class="price" style="width:100px;">
                                          <input type="hidden" value="{{$source_pic->price}}">
                                          <input type="hidden" value="{{$source_pic->source_pic_id}}">
                                        @else
                                        {{isset($source_pic->price)?$source_pic->price:""}}
                                        @endif
                                        </td>
                                        <td class="center ">
                                            @if(isset($source_pic->audit_state)&&($source_pic->audit_state==0||$source_pic->audit_state==2))
                                                <input type="text"  name="name" value="{{$source_pic->name}}" class="name" style="width:100px;">
                                                <input type="hidden" value="{{$source_pic->name}}">
                                                <input type="hidden" value="{{$source_pic->source_pic_id}}">
                                            @else
                                                {{isset($source_pic->name)?$source_pic->name:""}}
                                            @endif
                                        </td>
                                        <td class="center ">
                                            @if($source_pic->audit_state==0)
                                                还未提交审核，请在编辑中提交审核
                                            @elseif(isset($source_pic->audit_state)&&($source_pic->audit_state==2))
                                                已通过
                                            @elseif(isset($source_pic->audit_state)&&($source_pic->audit_state==3))
                                                不通过
                                            @else
                                                审核中
                                            @endif
                                        </td>
                                        <td class="project-actions">
                                            <button class="btn btn-info " type="button" onclick="deleteSourcePic('{{isset($source_pic->source_pic_id)?$source_pic->source_pic_id:""}}') ;"><i class="fa fa-paste"></i> 删除</button>
                                            @if(isset($source_pic->audit_state)&&($source_pic->audit_state==1))
                                                <button class="btn btn-info " ><i class="fa fa-paste"></i> 审核期间不能编辑</button>
                                            @else
                                            <button class="btn btn-info " type="button" onclick="javascript:window.location.href='{{asset('')}}/front/source-pic/update?id={{isset($source_pic->source_pic_id)?$source_pic->source_pic_id:""}}';"><i class="fa fa-paste"></i> 编辑</button>
                                            @endif
                                        </td>
                                    </tr>
                                    <?php $i++;?>
                                    @endforeach
                            </tbody>
                            <tfoot>

                            </tfoot>
                        </table>

                        <div class="row">
                            <div class="col-sm-6">

                            </div>
                            <div class="col-sm-6">
                                <div class="dataTables_paginate paging_simple_numbers"
                                     id="DataTables_Table_0_paginate">
                                    <?php echo $source_pics->render(); ?>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>


            </div>
        </div>
    </div>
</div>

<!-- 全局js -->
<script src="/front/hAdmin/js/jquery.min.js?v=2.1.4"></script>
<script src="/front/hAdmin/js/bootstrap.min.js?v=3.3.6"></script>

<!-- 自定义js -->
<script src="/front/hAdmin/js/content.js?v=1.0.0"></script>

<script src="/front/hAdmin/js/plugins/jeditable/jquery.jeditable.js"></script>
<!-- Data Tables -->
<script src="/front/hAdmin/js/plugins/dataTables/jquery.dataTables.js"></script>
<script src="/front/hAdmin/js/plugins/dataTables/dataTables.bootstrap.js"></script>
<script src="/js/dist/sweetalert-dev.js"></script>
<link rel="stylesheet" href="/js/dist/sweetalert.css">
<script type="application/javascript">
    $(function () {
        var update_price_state=1;
        var update_name_state=1;
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        $("#my-source-pic-manage").parent().addClass("active");
        $("#my-source-pic-manage").parent().siblings().removeClass("active");
        $(".price").blur(function(){
            var price = $(this).val();
            var id = $(this).next().next().val();
            var a = $(this);
            if((id==0)||(update_price_state==0)){
                swal({
                    title: "获取数据出错，稍后再试！",
                    text: "",
                    type: "error",
                    timer:600
                });
                update_price_state=1;
               return;
            }
            swal('处理中，请稍后','','warning');
            update_price_state=0;
            $.ajax({
                type: "POST",
                url: "/front/source-pic/update-price",
                data:{"price":price,"id":id},
                success: function(msg){
                    if(msg.state==1){
                        swal({
                            title: "更新成功！",
                            text: "",
                            type: "success",
                            timer:500
                        });
                    }else {
                        swal({
                            title: msg.message,
                            text: "",
                            type: "error",
                            timer:500
                        });
                    }
                },
                error:function(){
                    swal({
                        title: "系统繁忙稍后再试",
                        text: "",
                        type: "error",
                        timer:700
                    });
                }
            });
            update_price_state=1;
        });
        $(".name").blur(function(){
            var name = $(this).val();
            var id = $(this).next().next().val();
            if((id==0)||(update_name_state==0)){
                swal({
                    title: "获取数据出错，稍后再试！",
                    text: "",
                    type: "error",
                    timer:600
                });
                update_name_state=1;
                return;
            }
            swal('处理中，请稍后','','warning');
            update_name_state=0;
            $.ajax({
                type: "POST",
                url: "/front/source-pic/update-source-pic-name",
                data:{"name":name,"id":id},
                success: function(msg){
                    if(msg.state==1){
                        swal({
                            title: "更新成功！",
                            text: "",
                            type: "success",
                            timer:500
                        });
                    }else {
                        swal({
                            title: msg.message,
                            text: "",
                            type: "error",
                            timer:500
                        });
                    }
                },
                error:function(){
                    swal({
                        title: "系统繁忙稍后再试",
                        text: "",
                        type: "error",
                        timer:700
                    });
                }
            });
            update_name_state=1;
        });
        $('#filter_btn').click(function() {
            var url_para='';
            var is_shelves=parseInt($('#is_shelves option:selected').val());
            var audit_state=parseInt($('#audit_state option:selected').val());
            window.location.href="/front/source-pic/all?is_shelves="+is_shelves+'&audit_state='+audit_state;
        });
    });

    function deleteSourcePic(id) {
        if(id!=''){
            swal({
                title: "确定删除？？",
                text: "",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: true,
                closeOnCancel: true
            },function (){
                $.ajax({
                    type: "POST",
                    url: "/front/source-pic/delete",
                    data: {'id':id},
                    success: function (msg) {
                        if(msg.state==1){
                            swal({title: "删除成功！", text: "",type: "success", timer:1000 })
                            $('[data-tr-id='+id+']').remove();
                        }else {
                            swal({title: msg.message, text: "",type: "error", timer:1000 })
                        }

                    }, error: function () {
                        swal({title: "系统繁忙！", text: "",type: "error", timer:1000 })
                    }
                });
            });
        }
    }
</script>
</body>

</html>
